package com.taoli.service.impl;

import com.taoli.entity.Wallet;
import com.taoli.repository.WalletRepository;
import com.taoli.service.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class WalletServiceImpl implements WalletService {
    @Autowired
    private WalletRepository walletRepository;

    /**
    * @Description: 根据用户ID查询余额信息
    * @author: 韦武朝
    * @date: 2023/2/16 20:37
    * @param userId: 用户ID
    * @Return: com.taoli.entity.Wallet
    */
    @Override
    public Wallet getBalanceByUserId(Long userId) {
        Optional<Wallet> optional = walletRepository.findById(userId);
        Wallet wallet = null;
        try {
            wallet = optional.get();
        }catch (Exception e){

        }
        return wallet;
    }

    /**
    * @Description: 保存用户余额信息
    * @author: 韦武朝
    * @date: 2023/2/16 20:38
    * @param wallet: 用户余额实体
    * @Return: com.taoli.entity.Wallet
    */
    @Override
    public Wallet save(Wallet wallet) {
        return walletRepository.save(wallet);
    }
}
